package org.example.weboj.service.impl;

import org.example.weboj.entity.TestCases;
import org.example.weboj.mapper.TestCasesMapper;
import org.example.weboj.service.ITestCasesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 测试用例服务实现类
 * </p>
 *
 * @author wza
 * @since 2025-04-03
 */
@Service
public class TestCasesServiceImpl extends ServiceImpl<TestCasesMapper, TestCases> implements ITestCasesService {

    @Override
    public List<TestCases> getByProblemId(Long problemId) {
        return baseMapper.selectByProblemId(problemId);
    }

    @Override
    public List<TestCases> getSampleByProblemId(Long problemId) {
        return baseMapper.selectSampleByProblemId(problemId);
    }

    @Override
    public List<TestCases> getNonSampleByProblemId(Long problemId) {
        return baseMapper.selectNonSampleByProblemId(problemId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatch(List<TestCases> testCases) {
        if (testCases == null || testCases.isEmpty()) {
            return false;
        }
        return baseMapper.batchInsert(testCases) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByProblemId(Long problemId) {
        return baseMapper.deleteByProblemId(problemId) > 0;
    }
}
